package com.hospital.demo.controller.jiashuai;

import com.alibaba.fastjson.JSON;
import com.hospital.demo.model.jiashuai.Branch;
import com.hospital.demo.model.jiashuai.Department;
import com.hospital.demo.model.jiashuai.TWorker;
import com.hospital.demo.model.jiashuai.Worker;
import com.hospital.demo.service.jiashuai.IBranchService;
import com.hospital.demo.service.jiashuai.IDepartmentService;
import com.hospital.demo.service.jiashuai.ITWorkerService;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService iDepartmentService;

    @Autowired
    private ITWorkerService itWorkerService;

    @Autowired
    private IBranchService iBranchService;
    /**
     * 获取所有科室
     */
    @GetMapping("/getDepartment")
    public ResultVO getDepartment(){
        List<Department> list=iDepartmentService.selectDepartment();
        return ResultUtils.success(list);
    }

    /**
     * 删除科室
     */
    @GetMapping("/delDepartment")
    public ResultVO delDepartment(int mid){
        return ResultUtils.success(iDepartmentService.delDepartment(mid));
    }

    /**
     * 添加科室
     */
    @GetMapping("/addDepartment")
    public ResultVO addDepartment(Department department){
        return ResultUtils.success(iDepartmentService.addDepartment(department));
    }


    /**
     * 获取所有临时工
     */
    @GetMapping("/selectTWorker")
    @ResponseBody
    public ResultVO selectTWorker(){
        return ResultUtils.success(itWorkerService.selectTWorker());
    }


    /**
     * 辞职临时工
     */
    @GetMapping("/resignid")
    @ResponseBody
    public ResultVO resignid(int id){
        return ResultUtils.success(itWorkerService.resignid(id));
    }

    /**
     * 展示全部部门
     */
    @GetMapping("/selectBranch")
    @ResponseBody
    public ResultVO selectBranch(){
        return ResultUtils.success(iBranchService.selectBranch());
    }

    /**
     * 删除部门
     */
    @GetMapping("/delBranch")
    @ResponseBody
    public ResultVO delBranch(int id){
        return ResultUtils.success(iBranchService.delBranch(id));
    }

    /**
     * 添加部门
     */
    @GetMapping("/addBreach")
    @ResponseBody
    public ResultVO addBreach(Branch branch){
        return ResultUtils.success(iBranchService.addBreach(branch));
    }


    /**
     * 按照部门bid查找临时工
     */
    @GetMapping("/selectTWorkerByDepartment")
    public ResultVO selectTWorkerByDepartment(int did) {
        return ResultUtils.success(itWorkerService.selectTWorkerByDepartment(did));
    }


    /**
     * 按照id查找临时工
     */
    @GetMapping("/selectTWorkerByid")
    public ResultVO selectTWorkerByid(int id) {
        return ResultUtils.success(itWorkerService.selectTWorkerByid(id));
    }

    /**
     * 按照id查找临时工
     */
    @PostMapping("/addTworker")
    public ResultVO addTworker(TWorker tWorker) {
        return ResultUtils.success(itWorkerService.addTworker(tWorker));
    }
}
